package com.itheima.googleplay9.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.itheima.googleplay9.bean.PageInfo;

import java.util.ArrayList;

/**
 * Created by lxj on 2016/5/23.
 */
public class MainPagerAdapter extends FragmentPagerAdapter{
    private ArrayList<PageInfo> pageInfos;
    public MainPagerAdapter(FragmentManager fm, ArrayList<PageInfo> pageInfos) {
        super(fm);
        this.pageInfos = pageInfos;
    }
    @Override
    public Fragment getItem(int position) {
        return pageInfos.get(position).fragment;
    }
    @Override
    public int getCount() {
        return pageInfos.size();
    }

    /**
     * 返回每一页的标题
     * @param position
     * @return
     */
    @Override
    public CharSequence getPageTitle(int position) {
        return pageInfos.get(position).title;
    }
}
